package com.wmlive.hhvideo.widget.dialog;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import cn.wmlive.hhvideo.R;

/**
 * Created by vhawk on 2017/6/20.
 */

public class LoadingTransparentDialog extends Dialog {
    private Context context;
    private ImageView ivLoading;
    private Animator musicAnimator;

    public LoadingTransparentDialog(Context context) {
        super(context, R.style.BaseDialogThemeNoBackground);
        this.context = context;
        initView();
    }

    private void initView() {
        View view = View.inflate(context, R.layout.dialog_transparentbg_loading,null);
        ivLoading = (ImageView) view.findViewById(R.id.iv_loading);
        setContentView(view);
    }

    private void initAnimator() {
        musicAnimator = AnimatorInflater.loadAnimator(context, R.animator.loading);
        musicAnimator.setInterpolator(new LinearInterpolator());
        musicAnimator.setTarget(ivLoading);
    }

    @Override
    public void show() {
        super.show();
        initAnimator();
        musicAnimator.start();
    }

    @Override
    public void dismiss() {
        musicAnimator.cancel();
        musicAnimator = null;
        super.dismiss();
    }
}
